package cn.wgx.module.question.web;

import cn.wgx.module.base.web.BaseController;
import cn.wgx.module.question.entity.QQuestion;
import cn.wgx.module.question.service.QQuestionService;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api(tags = "")
@RestController
@RequestMapping(path = "api/qQuestion")
public class QQuestionController extends BaseController {

    @Resource
    QQuestionService service;

    @ApiOperation(value = "列表", notes = "" )
    @RequestMapping(path = "list", method = RequestMethod.GET)
    public Map<String, Object> getList(
            @ModelAttribute QQuestion record, 
			@RequestParam(value = "page", required = false, defaultValue = "1")Integer page,
			@RequestParam(value = "pageSize", required = false, defaultValue = "20")Integer pageSize,
            @ApiParam(value = "是否倒序,默认是")@RequestParam(defaultValue = "true", required = false)Boolean desc
        ) {
		return returnData(PageHelper.startPage(page, pageSize), service.getList(record, desc));
    }

	
    @ApiOperation(value = "获取单个", notes = "" )
    @RequestMapping(path = "get", method = RequestMethod.GET)
    public Map<String, Object> getOne(Integer id) {
		return returnData(service.getOne(id));
    }

	
    @ApiOperation(value = "新建", notes = "必须参数: " )
    @RequestMapping(path = "add", method = RequestMethod.POST)
    public Map<String, Object> insertOne(@RequestBody QQuestion record) {
        return returnData(service.insertOne(record));
    }



    @ApiOperation(value = "导入EXCEL", notes = "必须参数: " )
    @RequestMapping(path = "addByExcel", method = RequestMethod.POST)
    public Map<String, Object> updateExcel(MultipartFile file) {

        return returnData(service.addByExcel(file));
    }



    @ApiOperation(value = "修改", notes = "" )
    @RequestMapping(path = "update", method = RequestMethod.PATCH)
    public Map<String, Object> updateOne(@RequestBody QQuestion record) {
        return returnData(service.updateOne(record));

    }


    @ApiOperation(value = "删除", notes = "" )
    @RequestMapping(path = "del", method = RequestMethod.DELETE)
    public Map<String, Object> delete(@RequestBody List<Integer> ids) {
        return returnData(service.delete(ids));
    }
	

}